#pragma once
#include <list>
#include "vertex_buffer.h"
#include "index_buffer.h"

namespace krryn{
namespace view{
	class effect;
}
namespace scene{
	class renderable{
	public:
		typedef std::list<krryn::view::effect*> effect_list_t;

		virtual effect_list_t &effects() = 0;
		virtual void draw() = 0;
	};

	template<typename _RenderTag, typename _VertexType = scene::vertex>
	class mesh : public renderable{
	public:
		typedef mesh* ptr;
		typedef typename vertex_buffer<_RenderTag, _VertexType>::ptr vb_ptr;
		typedef typename index_buffer<_RenderTag>::ptr ib_ptr;

		mesh(vb_ptr a_VertexBuffer, ib_ptr a_IndexBuffer) 
			: m_VertexBuffer(a_VertexBuffer), m_IndexBuffer(a_IndexBuffer){}

		virtual void draw(){
			hardware_locker l_VertexRiaa(*m_VertexBuffer, read);
			hardware_locker l_IndexRiaa(*m_IndexBuffer, read);

			m_VertexBuffer->draw_indexed(*m_IndexBuffer);
		}

		virtual effect_list_t &effects(){return m_Effects;}
		int tri_count() { return m_IndexBuffer->size() / 3; }
	private:
		effect_list_t m_Effects;
		vb_ptr m_VertexBuffer;
		ib_ptr m_IndexBuffer;
	};
}
}